var e = require('../../../../@babel/runtime/helpers/regeneratorRuntime'),
  t = require('../../../../@babel/runtime/helpers/asyncToGenerator'),
  n = getApp();
Component({
  properties: {
    item: {
      type: Object,
      value: {},
      observer: function (e) {
        this._init(e);
      },
    },
    lose: { type: Boolean, value: !1 },
  },
  data: { nums: 1, goodsNumLimit: {}, step: 1 },
  attached: function () {
    var e = this.properties.item;
    this.setData({
      goodsNumLimit: {
        single_min: +e.single_min,
        single_max: +e.single_max,
        limit_max: +e.limit_max,
        day_max: +e.day_max,
        zu_num: +e.zu_num,
        is_zu: +e.zu_num ? 1 : 0,
        haveInitNum: !0,
        initNum: e.nums,
      },
      step: +e.zu_num ? +e.zu_num : 1,
    });
  },
  methods: {
    _init: function (e) {
      this.setData({ nums: parseInt(e.nums) });
    },
    _jumpTo: function (e) {
      var t = e.currentTarget.dataset.url;
      wx.navigateTo({ url: t });
    },
    _chooseSku: function () {
      var e = this.properties.item;
      this.triggerEvent('handChangeSku', e);
    },
    _numChange: function (a) {
      var r = this;
      return t(
        e().mark(function t() {
          var i, u, s, o, m, c, h;
          return e().wrap(function (e) {
            for (;;)
              switch ((e.prev = e.next)) {
                case 0:
                  if (
                    ((i = r.data),
                    (u = i.item),
                    (s = i.nums),
                    (o = r),
                    (m = a.detail.thisNum),
                    console.log(a),
                    (h = Math.abs(m - s)),
                    m > s && (c = 'addShopCar2'),
                    m < s && (c = 'subtractShopCar'),
                    m != s)
                  ) {
                    e.next = 9;
                    break;
                  }
                  return e.abrupt('return');
                case 9:
                  return (
                    (e.next = 11),
                    n.$api.order[c]({ num: h, cart_id: u.id })
                      .then(function () {
                        o.triggerEvent('handThisNum', { thisNum: m }),
                          n.$api.goods.getShopCarNums().then(function (e) {
                            wx.setStorageSync('__cartNum', e);
                          });
                      })
                      .catch(function (e) {
                        (m = s),
                          console.error('_numChange error: ', e),
                          r
                            .selectComponent('#'.concat(a.target.id))
                            ._numChange(m, !0);
                      })
                  );
                case 11:
                  console.log(m), r.setData({ nums: m });
                case 13:
                case 'end':
                  return e.stop();
              }
          }, t);
        }),
      )();
    },
  },
});
